package timing.ukulele.third.controller.weixin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import timing.ukulele.common.data.ResponseData;
import timing.ukulele.data.third.data.weixin.WxAppDTO;
import timing.ukulele.data.third.view.weixin.WxAppVO;
import timing.ukulele.third.service.weixin.WxAppService;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/weixin/wxApp")
public class WxAppController {

    private final WxAppService wxAppService;

    public WxAppController(WxAppService wxAppService) {
        this.wxAppService = wxAppService;
    }

    /**
     * /wxApp/saveWxApp
     * @param wxAppDTO
     * @return
     */
    @Operation(summary = "新增微信公众号")
    @PostMapping("/saveWxApp")
    public ResponseData<Boolean> saveWxApp(@RequestBody WxAppDTO wxAppDTO) {
        return ResponseData.success(wxAppService.saveWxApp(wxAppDTO));
    }

    /**
     * /wxApp/updateWxApp
     * @param wxAppDTO
     * @return
     */
    @Operation(summary = "修改微信公众号")
    @PutMapping("/updateWxApp")
    public ResponseData<Boolean> updateWxApp(@RequestBody WxAppDTO wxAppDTO) {
        return ResponseData.success(wxAppService.updateWxApp(wxAppDTO));
    }

    /**
     * /wxApp/getDetails
     * @param id
     * @return
     */
    @Operation(summary = "获取微信公众号详情")
    @GetMapping("/getDetails")
    public ResponseData<WxAppVO> getDetails(Long id) {
        return ResponseData.success(wxAppService.getDetails(id));
    }

    /**
     * /wxApp/allList
     * @return
     */
    @Operation(summary = "全部列表")
    @GetMapping("/allList")
    public ResponseData<List<WxAppVO>> allList(@RequestParam("appType") String appType) {
        return ResponseData.success(wxAppService.allList(appType));
    }

    /**
     * /wxApp/page
     * @param wxAppDTO
     * @return
     */
    @Operation(summary = "分页列表")
    @PostMapping("/page")
    public ResponseData<IPage<WxAppVO>> pageList(@RequestBody WxAppDTO wxAppDTO) {
        return ResponseData.success(wxAppService.pageList(wxAppDTO));
    }

    /**
     * /wxApp/generateQrCode
     * @param wxAppDTO
     * @return
     * @throws Exception
     */
    @Operation(summary = "生成公众号二维码")
    @PostMapping("/generateQrCode")
    public ResponseData<String> generateQrCode(WxAppDTO wxAppDTO) throws Exception {
        return ResponseData.success(wxAppService.generateQrCode(wxAppDTO));
    }

    /**
     * /wxApp/generateAndSaveQrCode
     * @param wxAppDTO
     * @return
     * @throws Exception
     */
    @Operation(summary = "生成并保存公众号二维码")
    @PostMapping("/generateAndSaveQrCode")
    public ResponseData<String> generateAndSaveQrCode(WxAppDTO wxAppDTO) throws Exception {
        return ResponseData.success(wxAppService.generateAndSaveQrCode(wxAppDTO));
    }

    /**
     * /wxApp/wxApiResetToZero
     * @param id
     * @return
     */
    @Operation(summary = "微信接口次数进行清零")
    @GetMapping("/wxApiResetToZero")
    public ResponseData<Boolean> wxApiResetToZero(Long id) throws Exception {
        return ResponseData.success(wxAppService.wxApiResetToZero(id));
    }

    /**
     * /wxApp/getAccessToken
     * @param id
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取access-token")
    @GetMapping("/getAccessToken")
    public ResponseData<String> getAccessToken(Long id) throws Exception {
        return ResponseData.success(wxAppService.getAccessToken(id));
    }

    /**
     * /wxApp/getJsapiTicket
     * @param id
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取jsapi-ticket")
    @GetMapping("/getJsapiTicket")
    public ResponseData<String> getJsapiTicket(Long id) throws Exception {
        return ResponseData.success(wxAppService.getJsapiTicket(id));
    }

}
